

cd "../replication-package"

*** ---------------------------------------------------- ***
**# ----- 6. Proportion of evangelical protestants ----- #**
*** ---------------------------------------------------- ***

clear all 
// following Homan 2019, calculating the percent state population composed of religious conservatives (Evangelical or LDS)
// ARDA has created a variable called "religions tradition category" based on Steensland et al 2000 
// https://www.thearda.com/data-archive?fid=RCMSMGST
use "data/raw/Longitudinal Religious Congregations and Membership File, 1980-2010 (State Level).DTA"

fre reltrad 
gen evanpro_dum = reltrad==1 

tab year // 1980, 1990, 2000, and 2010 

collapse (mean) evanpro_dum, by(year stfip)
gen state_a = stfip 
label define state_a  1 "AL" 2 "AK" 5 "AR" 4 "AZ" 6 "CA" 8 "CO" 9 "CT" 10 "DE" ///
		11 "DC" 12 "FL" 13 "GA" 15 "HI" 16 "ID" 19 "IA" 17 "IL" 18 "IN" 20 "KS" 21 "KY" 22 "LA" ///
		25 "MA" 24 "MD" 23 "ME" 26 "MI" 27 "MN" 29 "MO" 28 "MS" 30 "MT" 37 "NC" 38 "ND" ///
		31 "NE" 33 "NH" 34 "NJ" 35 "NM" 32 "NV" 36 "NY" 39 "OH" 40 "OK" 41 "OR" 42 "PA" ///
		44 "RI" 45 "SC" 46 "SD" 47 "TN" 48 "TX" 49 "UT" 51 "VA" 50 "VT" 53 "WA" 55 "WI" ///
		54 "WV" 56 "WY", replace
label val state_a state_a
drop stfip 

// use linear extrapolation to fill in missing years from 1980 to 2010  
// to do that, first generate a 'blank' state X year file that has full info 1980-2020 
preserve 
keep state_a 
bys state_a: keep if _n==1 
expand 41, gen(year_m)
sort state_a year_m
bys state_a: replace year_m = _n
replace year_m = year_m + 1979
tab year_m
tempfile fullyears 
save `fullyears', replace 
restore 

gen year_m = year 
merge 1:1 year_m state_a using `fullyears', nogen
sort state_a year_m

// linear extrapolation 
bys state_a (year_m): ipolate evanpro_dum year_m, gen(evanpro_dum_m)

// fill in the 'missing' years, after 2010 
bys state_a (year_m): replace evanpro_dum_m = evanpro_dum_m[_n-1] if evanpro_dum_m==. & evanpro_dum_m[_n-1]!=.
keep if inrange(year_m, 1980, 2020)

keep state_a year_m evanpro_dum*
order state_a year_m evanpro_dum evanpro_dum_m
rename year_m year

save "data/state/06_evanpro_ARDA.dta", replace 
